/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.math;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/8
 */
public class Lesson5_1_p {

    public static List<List<Integer>> answer(int target) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> r1 = new ArrayList<>();
        r1.add(1);
        r1.add(target);
        List<Integer> r2 = new ArrayList<>();
        r2.add(target);
        r2.add(1);
        result.add(r1);
        result.add(r2);
        dg(target, target, new ArrayList<>(), result);
        return result;
    }

    public static void dg(int target, int temp, ArrayList<Integer> tempList, List<List<Integer>> result) {
        if (temp == 1) {
            result.add(tempList);
            return;
        }
        int len = temp >> 1;
        for (int i = 2; i <= len; i++) {
            if (temp % i == 0) {
                ArrayList<Integer> newTempList = (ArrayList<Integer>)(tempList.clone());
                newTempList.add(i);
                dg(target, temp / i, newTempList, result);
            }
        }
        if (temp != target) {
            ArrayList<Integer> newTempList = (ArrayList<Integer>)(tempList.clone());
            newTempList.add(temp);
            dg(target, 1, newTempList, result);
        }
    }

    public static void main(String[] args) {
        System.out.println(answer(18));
    }
}
